const define = {
    state: () => (
        {
            // 列表
            list: []
        }
    ),
    actions: {
        // 获取列表
        getList() {
            return this.list;
        },
        // 设置列表
        setList(list) {
            this.list = list;
        },
        getListTop() {
            const list = this.list.filter(item => {
                return !item.parentId;
            });
            list.map(item=> {
                if (item.path) {
                    item.path = item.path.trim();
                }
            });
            return list;
        },
        getSubMenuList(parentId) {
            const subMenuList = this.list.filter(item => {
                return parentId === item.parentId;
            });
            subMenuList.map(item=> {
                if (item.path) {
                    item.path = item.path.trim();
                }
            });
            if (subMenuList && subMenuList) {
                subMenuList.forEach(item => {
                    item.children = this.getSubMenuList(item.menuId);
                })
            }
            return subMenuList;
        }
    }
}

const useStore = defineStore('menu', define);

export default useStore